--忠佐
local zhongzuo = fk.CreateSkill {
    name = "mcdh_zhongzuo",
    tags = {Skill.Compulsory}
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

zhongzuo:addEffect(fk.Damaged,{
    can_trigger = function(self, event, target, player, data)
        if event ==  fk.GameStart then
            return player:hasSkill(self)
        else
            return player:hasSkill(self) and target.role == "lord"
        end

    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local skills={}
        for name, s in pairs(Fk.skills) do
            if s.isPlayerSkill and s.visible then
                if string.find(Fk:translate("$"..name.."1", "zh_CN"), "忠") or
                        string.find(Fk:translate("$"..name.."2", "zh_CN"), "忠") then  --暂时先这样，多句台词或者固定技能池看反馈
                    table.insertIfNeed(skills, name)
                end
                if string.find(Fk:translate(name, "zh_CN"), "忠") then
                    table.insertIfNeed(skills, name)
                end
            end
        end
        if #skills > 0 then
            local s = table.random(skills)
            if string.find(Fk:translate("$"..s.."1", "zh_CN"), "忠") then
                player:chat(string.format("$%s:%d", s, 1))
            elseif string.find(Fk:translate("$"..s.."2", "zh_CN"), "忠") then
                player:chat(string.format("$%s:%d", s, 2))
            else
                player:chat(string.format("$%s:%d", s, 1))
            end
            if player:hasSkill(s,true) then
                room:handleAddLoseSkills(player, "-" + s, nil, true, false)
            else
                room:handleAddLoseSkills(player, s, nil, true, false)
            end

        end
    end
})


zhongzuo:addEffect(fk.GameStart,{
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self) and target.role == "lord"
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local skills={}
        for name, s in pairs(Fk.skills) do
            if s.isPlayerSkill and s.visible then
                if string.find(Fk:translate("$"..name.."1", "zh_CN"), "忠") or
                        string.find(Fk:translate("$"..name.."2", "zh_CN"), "忠") then  --暂时先这样，多句台词或者固定技能池看反馈
                    table.insertIfNeed(skills, name)
                end
                if string.find(Fk:translate(name, "zh_CN"), "忠") then
                    table.insertIfNeed(skills, name)
                end
            end
        end
        if #skills > 0 then
            local s = table.random(skills)
            if string.find(Fk:translate("$"..s.."1", "zh_CN"), "忠") then
                player:chat(string.format("$%s:%d", s, 1))
            elseif string.find(Fk:translate("$"..s.."2", "zh_CN"), "忠") then
                player:chat(string.format("$%s:%d", s, 2))
            else
                player:chat(string.format("$%s:%d", s, 1))
            end
            if player:hasSkill(s,true) then
                room:handleAddLoseSkills(player, "-" + s, nil, true, false)
            else
                room:handleAddLoseSkills(player, s, nil, true, false)
            end
        end
    end
})


Fk:loadTranslationTable{
    ["mcdh_zhongzuo"] = "忠佐",
    [":mcdh_zhongzuo"]="锁定技,游戏开始时或主公受到伤害后,你获得一个技能名或技能台词含\"忠\"的技能(若已有则失去之)"
}

return zhongzuo